package com.example.backend.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.backend.common.api.R;
import com.example.backend.entity.EmailLog;
import com.example.backend.service.EmailLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 邮件日志控制器
 */
@RestController
@RequestMapping("/admin/email/log")
@RequiredArgsConstructor
public class EmailLogController {
    
    private final EmailLogService emailLogService;
    
    /**
     * 分页查询邮件日志
     */
    @GetMapping("/list")
    @PreAuthorize("hasAuthority('system:email:log:list')")
    public R<IPage<EmailLog>> list(@RequestParam(defaultValue = "1") Integer pageNum,
                                  @RequestParam(defaultValue = "10") Integer pageSize) {
        return R.ok(emailLogService.page(new Page<>(pageNum, pageSize)));
    }
    
    /**
     * 删除邮件日志
     */
    @DeleteMapping("/{id}")
    @PreAuthorize("hasAuthority('system:email:log:delete')")
    public R<Void> delete(@PathVariable Long id) {
        return emailLogService.removeById(id) ? R.ok() : R.fail("删除失败");
    }
    
    /**
     * 清理邮件日志
     */
    @DeleteMapping("/clean")
    @PreAuthorize("hasAuthority('system:email:log:clean')")
    public R<Void> clean(@RequestParam(defaultValue = "30") Integer days) {
        // TODO: 实现清理逻辑
        return R.ok();
    }
} 